﻿using DevComponents.AdvTree;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WorkStation.Logic;

namespace WorkStation.UI.Controls
{
    public partial class HolderControl : UserControl
    {
        private Holder _holder;
        public HolderControl()
        {
            InitializeComponent();
        }
        public void SetHolder(Holder holder)
        {
            this._holder = holder;
        }
        public void UpdateStatus()
        {
            if (_holder != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (i == 0)
                    {
                        if(_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct && 
                           _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeOK)
                            l_Cell1.BackColor = Color.LimeGreen;
                        else if(_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeNG)
                            l_Cell1.BackColor = Color.OrangeRed;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.NoTest)
                            l_Cell1.BackColor = Color.Yellow;
                        else if(_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.NoProduct)
                            l_Cell1.BackColor = Color.Gray;
                    }
                    else if (i == 1)
                    {
                        if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                           _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeOK)
                            l_Cell2.BackColor = Color.LimeGreen;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeNG)
                            l_Cell2.BackColor = Color.OrangeRed;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.NoTest)
                            l_Cell2.BackColor = Color.Yellow;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.NoProduct)
                            l_Cell2.BackColor = Color.Gray;
                    }
                    else if (i == 2)
                    {
                        if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                          _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeOK)
                            l_Cell3.BackColor = Color.LimeGreen;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeNG)
                            l_Cell3.BackColor = Color.OrangeRed;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.NoTest)
                            l_Cell3.BackColor = Color.Yellow;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.NoProduct)
                            l_Cell3.BackColor = Color.Gray;
                    }
                    else if (i == 3)
                    {
                        if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                          _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeOK)
                            l_Cell4.BackColor = Color.LimeGreen;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.FirstTimeNG)
                            l_Cell4.BackColor = Color.OrangeRed;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.HasProduct &&
                                _holder.Helper.GetCell(i).Result == Kimd.Motion.TestResult.NoTest)
                            l_Cell4.BackColor = Color.Yellow;
                        else if (_holder.Helper.GetCell(i).Status == Kimd.Motion.CellStatus.NoProduct)
                            l_Cell4.BackColor = Color.Gray;
                    }
                }
                for (int i = 0; i < 4; i++)
                {
                    if (i == 0)
                        l_Mirror1.BackColor = _holder.MirrorStatus[i] ? Color.LimeGreen : Color.Gray;
                    else if (i == 1)
                        l_Mirror2.BackColor = _holder.MirrorStatus[i] ? Color.LimeGreen : Color.Gray;
                    else if (i == 2)
                        l_Mirror3.BackColor = _holder.MirrorStatus[i] ? Color.LimeGreen : Color.Gray;
                    else if (i == 3)
                        l_Mirror4.BackColor = _holder.MirrorStatus[i] ? Color.LimeGreen : Color.Gray;
                }
            }
        }
    }
}
